package cn.zwxky.android.staff.Jurisdiction.Technology;

import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.LsfbLog;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.Follow.ArrangeAdapter;
import cn.zwxky.android.staff.Follow.ArrangeClickEvent;
import cn.zwxky.android.staff.Follow.ArrangeFollowActivity;
import cn.zwxky.android.staff.Follow.NormalTaskBean;
import cn.zwxky.android.staff.Follow.NormalTaskEvent2;
import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * 技术部项目任务
 * Created by Administrator on 2017/3/31 0031.
 */
@ContentView(R.layout.aty_project_task)
public class ProjectTaskActivity extends LsfbActivity {


    /**
     * 点击刷新布局控件
     */
    @ViewInject(R.id.swiplayout)
    private SwipeRefreshLayout swipeRefreshLayout;

    /**
     * list列表
     */
    @ViewInject(R.id.dish_list)
    private RecyclerView dish_list;

    /**
     * RecyclerView的布局管理器
     */
    private RecyclerView.LayoutManager mlayoutManager;


    private List<NormalTaskBean.ListBean> mList;
    private ArrangeAdapter adapter;

    private String id;

    @Override
    public void initView() {

        id=getIntent().getStringExtra("id");

        mList=new ArrayList<>();
        adapter=new ArrangeAdapter(this,mList,R.layout.item_arrange);
        mlayoutManager = new LinearLayoutManager(this);//布局模式为listview方式
        dish_list.setLayoutManager(mlayoutManager);
        dish_list.setAdapter(adapter);

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getData();
            }
        });

        getData();
    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     * @param view
     */
    @OnClick({R.id.fg_back,R.id.fg_add})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.fg_back:
                finish();
                break;
            case R.id.fg_add:
               startActivity(new Intent(this, TechnologyReleaseTaskActivity.class).putExtra("id",id));
                break;
        }
    }

    @Override
    public void initData() {
        getData();
    }

    /**
     * 获取数据
     */
    public void getData(){
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("sid", id);
        new BaseInternet().getData_Get(URLString.PROTASK, hashMap, NormalTaskBean.class, new NormalTaskEvent2<NormalTaskBean>(), true,true);
    }

    @EventAnnotation
    public void NormalTaskEvent(NormalTaskEvent2<NormalTaskBean> event){
        LsfbLog.e("dasda");
        swipeRefreshLayout.setRefreshing(false);
        switch (event.getCode()){
            case 200:
                mList.clear();
                mList.addAll(event.getData().getList());
                adapter.notifyDataSetChanged();
                break;
            default:
                SN.SnackShow(dish_list,event.getMsg());
                break;
        }
    }

    @EventAnnotation
    public void ArrangeClickEvent(ArrangeClickEvent event){
        startActivity(new Intent(this,ArrangeFollowActivity.class).putExtra("id",event.getData()));
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }
}
